home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / TRNSFORM.CPP < prev    next >
Text File  |  1997-05-06  |  1KB  |  41 lines

  1.  #include <functional>
  2.  #include <deque>
  3.  #include <algorithm>
  4.  #include <iomanip.h>
  5.  
  6.  using namespace std;
  7.  
  8.  int main ()
  9.  {
  10.    //
  11.    // Initialize a deque with an array of integers.
  12.    //
  13.    int arr1[5] = {99, 264, 126, 330, 132};
  14.    int arr2[5] = {280, 105, 220, 84, 210};
  15.    deque<int> d1(arr1+0, arr1+5), d2(arr2+0, arr2+5);
  16.    //
  17.    // Print the original values.
  18.    //
  19.    cout << "The following pairs of numbers: " << endl << "     ";
  20.    deque<int>::iterator i1;
  21.    for (i1 = d1.begin(); i1 != d1.end(); i1++)
  22.       cout << setw(6) << *i1 << " ";
  23.    cout << endl << "     ";
  24.    for (i1 = d2.begin(); i1 != d2.end(); i1++)
  25.       cout << setw(6) << *i1 << " ";
  26.    //
  27.    // Transform the numbers in the deque to their
  28.    // factorials and store in the vector.
  29.    //
  30.    transform(d1.begin(), d1.end(), d2.begin(), d1.begin(), times<int>());
  31.    //
  32.    // Display the results.
  33.    //
  34.    cout << endl << endl;
  35.    cout << "Have the products: " << endl << "     ";
  36.    for (i1 = d1.begin(); i1 != d1.end(); i1++)
  37.      cout << setw(6) << *i1 << " ";
  38.  
  39.    return 0;
  40.  }
  41.